package com.yzyz.service.impl;

import java.util.List;

import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.yzyz.bean.scenic.DescriptionBean;
import com.yzyz.dao.DescriptionDao;
import com.yzyz.service.DescriptionService;
import com.yzyz.utils.error.Error;

/**
 * 景区描述
 * @author David Sun
 * @Date   2010-2-27
 *
 */
@Transactional
public class DescriptionServiceImpl implements DescriptionService {
	private DescriptionDao descriptionDao;
	@Override
	public List<DescriptionBean> listAll() {
		
		return this.descriptionDao.getAllDescription();
	}
	@Transactional(propagation = Propagation.REQUIRED,rollbackFor=Exception.class)
	@Override
	public int add(Object object) {
		this.descriptionDao.save(object);
		return Error.SUCCESS;
	}
	@Transactional(propagation = Propagation.REQUIRED,rollbackFor=Exception.class)
	@Override
	public int delete(int id) {
		if(this.descriptionDao.delete(id) != 1){
			return Error.OBJECT_NOT_EXIST;
		}
		return Error.SUCCESS;
	}

	@Override
	public Object find(int id) {
		return this.descriptionDao.get(id);
	}
	@Transactional(propagation = Propagation.REQUIRED,rollbackFor=Exception.class)
	@Override
	public int update(Object object) {
		DescriptionBean des = (DescriptionBean)object;
		if(this.descriptionDao.getByScenic(des.getOwnerId()) != null){
			this.descriptionDao.update(object);
		} else {
			this.descriptionDao.save(object);
		}
		return Error.SUCCESS;

	}

	@Override
	public void setDescriptionDao(DescriptionDao descriptionDao) {
		this.descriptionDao = descriptionDao;
		
	}

	@Override
	public DescriptionBean findByScenic(int scenicId) {
		return this.descriptionDao.getByScenic(scenicId);
	}
	@Override
	public List<?> paginate(int start, int limit) {
		// TODO Auto-generated method stub
		return null;
	}

}
